﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace WaffleControl.Converters
{
    class ValueMinusParameter : IValueConverter
    {
        /// <summary>
        /// Convert from source to UI
        /// </summary>
        /// <param name="value">source value</param>
        /// <param name="targetType">type of target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object Convert(object value, System.Type targetType, object parameter, string culture)
        {
            double x = (double)value;
            double y = 0;
            if (parameter != null)
                Double.TryParse((string)parameter, out y);
            if (x != 0 && x - y > 0)
                x = x - y;
            return (object)x;
        }
        /// <summary>
        /// Convert from UI to source
        /// </summary>
        /// <param name="value">UI value</param>
        /// <param name="targetType">type of the target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object ConvertBack(object value, System.Type targetType, object parameter, string culture)
        {
            throw new NotImplementedException();
        }
    }
    class ValueMinusParameterGL : IValueConverter
    {
        /// <summary>
        /// Convert from source to UI
        /// </summary>
        /// <param name="value">source value</param>
        /// <param name="targetType">type of target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object Convert(object value, System.Type targetType, object parameter, string culture)
        {
            double x = (double)value;
            double y = 0;
            if (parameter != null)
                Double.TryParse((string)parameter, out y);
            if (x != 0 && x - y > 0)
                x = x - y;
            return (object)new GridLength(x);
        }
        /// <summary>
        /// Convert from UI to source
        /// </summary>
        /// <param name="value">UI value</param>
        /// <param name="targetType">type of the target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object ConvertBack(object value, System.Type targetType, object parameter, string culture)
        {
            throw new NotImplementedException();
        }
    }
    class ValuePercentage : IValueConverter
    {
        /// <summary>
        /// Convert from source to UI
        /// </summary>
        /// <param name="value">source value</param>
        /// <param name="targetType">type of target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object Convert(object value, System.Type targetType, object parameter, string culture)
        {
            double x = (double)value;
            double y = 0;
            if (parameter != null)
                Double.TryParse((string)parameter, out y);
            x = (x / 100) * y;
            return (object)x;
        }
        /// <summary>
        /// Convert from UI to source
        /// </summary>
        /// <param name="value">UI value</param>
        /// <param name="targetType">type of the target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object ConvertBack(object value, System.Type targetType, object parameter, string culture)
        {
            throw new NotImplementedException();
        }
    }
    class ValuePercentageTile : IValueConverter
    {
        /// <summary>
        /// Convert from source to UI
        /// </summary>
        /// <param name="value">source value</param>
        /// <param name="targetType">type of target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object Convert(object value, System.Type targetType, object parameter, string culture)
        {
            double x = (double)value;
            double y = 0;
            if (parameter != null)
                Double.TryParse((string)parameter, out y);
#if WINDOWS_PHONE_APP
                x = (x / 100) * y;
#endif
#if WINDOWS_APP
            x = (x / 100) * (y / 5);
#endif
            return (object)x;
        }
        /// <summary>
        /// Convert from UI to source
        /// </summary>
        /// <param name="value">UI value</param>
        /// <param name="targetType">type of the target</param>
        /// <param name="parameter">optional params</param>
        /// <param name="culture">localization culture</param>
        /// <returns></returns>
        public object ConvertBack(object value, System.Type targetType, object parameter, string culture)
        {
            throw new NotImplementedException();
        }
    }
}